package com.xh.core.util;

import com.aspose.words.AbsolutePositionTab;
import com.aspose.words.DocumentVisitor;
import com.aspose.words.Run;
import com.aspose.words.VisitorAction;

public class DocTextExtractor extends DocumentVisitor
{
    public DocTextExtractor()
    {
        mBuilder = new StringBuilder();
    }

    /// <summary>
    /// Called when a Run node is encountered in the document.
    /// </summary>
    public int visitRun(final Run run) {
        appendText(run.getText());
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Called when an AbsolutePositionTab node is encountered in the document.
    /// </summary>
    public int visitAbsolutePositionTab(final AbsolutePositionTab tab) {
        mBuilder.append("\t");

        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Adds text to the current output. Honors the enabled/disabled output flag.
    /// </summary>
    public void appendText(final String text) {
        mBuilder.append(text);
    }

    /// <summary>
    /// Plain text of the document that was accumulated by the visitor.
    /// </summary>
    public String getText() {
        return mBuilder.toString();
    }

    private StringBuilder mBuilder;
}